from _typeshed import SupportsRead, SupportsWrite
from collections.abc import Callable, Iterator, Mapping
from typing import Any, Self, TypeVar

from ._version import __version__ as __version__

_T = TypeVar("_T")

DEFAULT_INTERPOLATION: str
DEFAULT_INDENT_TYPE: str

class UnknownType(Exception): ...
class ConfigObjError(SyntaxError): ...
class NestingError(ConfigObjError): ...
class ParseError(ConfigObjError): ...
class ReloadError(IOError): ...
class DuplicateError(ConfigObjError): ...
class ConfigspecError(ConfigObjError): ...
class InterpolationError(ConfigObjError): ...
class InterpolationLoopError(InterpolationError): ...
class RepeatSectionError(ConfigObjError): ...
class MissingInterpolationOption(InterpolationError): ...
class UnreprError(ConfigObjError): ...

class Section(dict[str, Any]):
    sections: list[str]
    def __setstate__(self, state) -> None: ...
    def __reduce__(
        self,
    ) -> tuple[
        Callable[..., Any], tuple[type[Self]], tuple[dict[Any, Any | str | list[Any | str] | list[Any]], dict[str, Any]]
    ]: ...
    def __getitem__(self, key: str) -> Any: ...
    def __setitem__(self, key: str, value: object, unrepr: bool = ...) -> None: ...
    def __delitem__(self, key: str) -> None: ...
    def get(self, key: str, default: Any = ...) -> Any: ...
    def update(self, indict: Mapping[str, Any]) -> None: ...  # pyright: ignore[reportIncompatibleMethodOverride]
    def pop(self, key: str, default: Any = ...) -> Any: ...
    def popitem(self) -> tuple[str, Any]: ...
    def clear(self) -> None: ...
    def setdefault(self, key: str, default: Any = ...) -> Any: ...
    def items(self) -> list[tuple[str, Any]]: ...  # pyright: ignore[reportIncompatibleMethodOverride]
    def keys(self) -> list[str]: ...  # pyright: ignore[reportIncompatibleMethodOverride]
    def values(self) -> list[Any]: ...  # pyright: ignore[reportIncompatibleMethodOverride]
    def iteritems(self) -> Iterator[tuple[str, Any]]: ...
    def iterkeys(self) -> Iterator[str]: ...
    def __iter__(self) -> Iterator[str]: ...
    def itervalues(self) -> Iterator[Any]: ...
    def dict(self) -> dict[str, Any]: ...
    def merge(self, indict: Mapping[str, Any]) -> None: ...
    def rename(self, oldkey: str, newkey: str) -> None: ...
    def walk(
        self, function: Callable[..., Any], raise_errors: bool = ..., call_on_sections: bool = ..., **keywargs: Any
    ) -> dict[str, Any]: ...
    def as_bool(self, key: str) -> bool: ...
    def as_int(self, key: str) -> int: ...
    def as_float(self, key: str) -> float: ...
    def as_list(self, key: str) -> list[Any]: ...
    def restore_default(self, key: str) -> Any: ...
    def restore_defaults(self) -> None: ...

class ConfigObj(Section):
    filename: str | None
    def __init__(
        self,
        infile: str | list[str] | tuple[str, ...] | dict[str, Any] | SupportsRead[str] | None = ...,
        configspec: object = ...,
        encoding: str | None = ...,
        interpolation: bool = ...,
        raise_errors: bool = ...,
        list_values: bool = ...,
        create_empty: bool = ...,
        file_error: bool = ...,
        stringify: bool = ...,
        indent_type: str = ...,
        default_encoding: str | None = ...,
        unrepr: bool = ...,
        write_empty_values: bool = ...,
        _inspec: bool = ...,
    ) -> None: ...
    def write(self, outfile: SupportsWrite[str] | None = ...) -> list[str] | None: ...
    def validate(self, validator: object, preserve_errors: bool = ..., copy: bool = ...) -> bool | dict[str, bool]: ...
    def reset(self) -> None: ...
    def reload(self) -> None: ...

class SimpleVal:
    def __init__(self) -> None: ...
    def check(self, check: object, member: _T, missing: bool = ...) -> _T: ...

def flatten_errors(cfg: ConfigObj, res: dict[str, bool]) -> list[Any]: ...
def get_extra_values(conf: ConfigObj) -> list[Any]: ...

__all__ = (
    "DEFAULT_INDENT_TYPE",
    "DEFAULT_INTERPOLATION",
    "ConfigObjError",
    "NestingError",
    "ParseError",
    "DuplicateError",
    "ConfigspecError",
    "ConfigObj",
    "SimpleVal",
    "InterpolationError",
    "InterpolationLoopError",
    "MissingInterpolationOption",
    "RepeatSectionError",
    "ReloadError",
    "UnreprError",
    "UnknownType",
    "flatten_errors",
    "get_extra_values",
)
